<template>
  <div class="tab-control">
    <template v-for="(item, index) in titles" :key="item">
      <div class="tab-control-item" :class="{active: index === currentIndex}"
      @click="clickItem(index)"><span>{{ item }}</span></div>
    </template>
  </div>
</template>

<script>
  export default {
    props: {
      titles: {
        types: Array,
        default: () => [] 
      }
    },
    data() {
      return {
        currentIndex: 0
      }
    },
    emits: ["clickItem"],
    methods: {
      clickItem(index) {
        this.currentIndex = index
        this.$emit("clickItem", index)
      }
    }
  }
</script>

<style scoped>
  .tab-control {
    display: flex;
    height: 44px;
    line-height: 44px;
    text-align: center;
    background-color: #fff;
    border-bottom: 1px solid #ccc;
  }
  .tab-control-item {
    flex: 1;
  }
  .tab-control-item.active span {
    color: red;
    border-bottom: 3px solid red;
    padding: 8px;
  }
</style>